Fix formatting of code longer than Discord's message limit#549
Conversation
danthe1st
left a comment
There was a problem hiding this comment.
Congratulations on writing your first pull request. I commented on a few things I noticed. Please don't unnecessarily duplicate code.
|
Fixes #537 |
…nto fix/format-code-long-messages # Conflicts: # src/main/java/net/discordjug/javabot/systems/user_commands/format_code/Code.java # src/main/java/net/discordjug/javabot/systems/user_commands/format_code/FormatCodeDispatcher.java # src/main/java/net/discordjug/javabot/systems/user_commands/format_code/Language.java
danthe1st
left a comment
There was a problem hiding this comment.
These are mostly minor comments. Is there any good reason why users would want a file response in addition to the codeblocks?
There was a problem hiding this comment.
Overall, your PR looks pretty good.
During testing, I noticed that it's possible to send a single message that can result in a lot of individual (and big). As an example, you can generate the content of such a message with the following code:
System.out.println("{".repeat(30)+"\n"+"a\n".repeat(1000)+"}".repeat(30));Please add a limit to this. I don't want to have to clean that up without knowing the exact number (I think it is possible to trigger more than 500 messages with a single message that way). See the second review comment here for how to fix it.
danthe1st
left a comment
There was a problem hiding this comment.
There's one small typo remaining, otherwise it looks good.
…nto fix/format-code-long-messages # Conflicts: # src/main/java/net/discordjug/javabot/systems/user_commands/format_code/FormatCodeDispatcher.java
Description of the Changes
The "Format Code" / "Format and Indent Code" message commands and the
/format-codeslash command failed when the target message was longer than Discord's 2000-character limit: the whole snippet was wrapped in a single code block and sent as one message, which Discord rejects — so the command silently did nothing.This PR splits the formatted output into chunks that each stay under the limit:
Codeclass splits content into ≤1980-character chunks (breaking on newlines where possible) and renders each as a code block.Languageenum +Language.fromString(...)maps the slash command'sformatoption to a code-fence tag.A follow-up PR will add the language-selection dropdown.